﻿package cn.poco.pepsi.util.xmlpared;

import java.io.InputStream;

import org.xmlpull.v1.XmlPullParser;

import android.util.Xml;
import cn.poco.pepsi.bean.Discount;

public class DisCountDetailXmlparse {
	//private final static String TAG = "GPSCityXmlparse";
	private static  Discount disCountBean = null;
	
	public static Discount getXml(InputStream inSteam) throws Exception{
		XmlPullParser xmpparse = Xml.newPullParser();   //得到解释器
		xmpparse.setInput(inSteam, "UTF-8");           //设置解释流
		int code = xmpparse.getEventType();            //得到节点信息
		while(code!=XmlPullParser.END_DOCUMENT){
			switch (code) {
			case XmlPullParser.START_TAG:
				try{
					if("discount".equals(xmpparse.getName())){
						disCountBean = new Discount();
					}
					if(disCountBean!=null){
						if ("info-id".equals(xmpparse.getName())) {
							String key = xmpparse.nextText();
							disCountBean.setDisID(Integer.parseInt(key));
						}
						if ("title".equals(xmpparse.getName())) {
							String key = xmpparse.nextText();
							disCountBean.setDisTitle(key);
						}
						if ("content".equals(xmpparse.getName())) {
							String key = xmpparse.nextText();
							disCountBean.setDisContent(key);
						}
						if ("top-image".equals(xmpparse.getName())) {
							String key = xmpparse.nextText();
							disCountBean.setDisPhoto(key);
						}
						if ("res-id".equals(xmpparse.getName())) {
							String key = xmpparse.nextText();
							disCountBean.setResID(key);
						}
						if ("res-title".equals(xmpparse.getName())) {
							String key = xmpparse.nextText();
							disCountBean.setResTitle(key);
						}
						if ("use-card".equals(xmpparse.getName())) {
							String key = xmpparse.nextText();
							disCountBean.setUseCard(Integer.parseInt(key));
						}
						if ("use-sms".equals(xmpparse.getName())) {
							String key = xmpparse.nextText();
							disCountBean.setUseSms(Integer.parseInt(key));
						}
						if ("is-pepsi".equals(xmpparse.getName())) {
							String key = xmpparse.nextText();
							disCountBean.setUserPepsi(Integer.parseInt(key));
						}
					}
				}catch(Exception e){
					e.toString();
				}
				
				break;
			}	
			code = xmpparse.next();
		}
		inSteam.close();
		return disCountBean;
	}
}
